package yf.mall.controller.api;

import com.yf.annotation.IgnoreAuth;
import yf.mall.entity.BannerEntity;
import yf.mall.entity.MallGoodsEntity;
import com.yf.response.R;
import yf.mall.service.BannerService;
import yf.mall.service.MallGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/home")
public class ApiHomeController {

    @Autowired
    private BannerService bannerService;

    @Autowired
    private MallGoodsService mallGoodsService;

    //首页
    @GetMapping({"/banner/{type}","/banner"})
    @IgnoreAuth
    public R banner(@PathVariable(required = false,name = "type") Integer type) {
        Map<String,Object> map = new HashMap<>();
        map.put("link_id",type);
        List<BannerEntity> bannerEntities = bannerService.queryList(map);
        return R.ok(bannerEntities);
    }

//    //产品 TODO 分页 隐藏字段
//    @GetMapping("/goods")
//    @IgnoreAuth
//    public R goods(int limit,int page) {
//        List<MallGoodsEntity> mallGoodsEntities = mallGoodsService.topList(limit,page);
//        return R.ok(mallGoodsEntities);
//    }

    //产品详情 TODO 隐藏字段
    @GetMapping("/goods/info/{id}")
    @IgnoreAuth
    public R info(@PathVariable("id") Long goodsId) {
        MallGoodsEntity mallGoodsEntity = mallGoodsService.getDetail(goodsId);
        return R.ok(mallGoodsEntity);
    }

}
